package controller;

import service.HotelEmployeeService;
import serviceImp.HotelEmployeeServiceImp;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Servlet implementation class RegisterController
 */
@WebServlet("/loginRegister/RegisterController.do")
public class RegisterController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegisterController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		String tel = request.getParameter("tel");
		String password = request.getParameter("password");
   		String rePassword = request.getParameter("rePassword");
		HotelEmployeeService hotelEmployeeService =new HotelEmployeeServiceImp();
		int code = hotelEmployeeService.register(tel,password);
		switch (code){
			case -1:
				request.setAttribute("regTip", "注册失败，该手机号已被占用");
				break;
			case 0:
				request.setAttribute("regTip", "注册失败，请重新跳转");
				break;
			case 1:
				request.setAttribute("regTip", "注册成功，请登录");
				break;
		}
		request.getRequestDispatcher("/loginRegister/loginRegister.jsp").forward(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
